package ua.luxoft.file;

import java.io.File;
import java.util.ArrayList;

public class FindFile {
	
	public FindFile(){}
	
	private File[] findAllFiles(File dir){
		return dir.listFiles();
	}
	
	private boolean checkIsFile(File file){
		return file.isFile();
	}
	
	private ArrayList<File> removeDirectoryFromList(File[] list){
		ArrayList<File> files = new ArrayList<File>();
		for( int i = 0; i < list.length; i++ ){
			if(checkIsFile(list[i])){
				files.add(list[i]);
			}
		}
		return files;
	}
	public ArrayList<File> getAllFilesInDir(String path){
		if(path == null){
			throw new IllegalArgumentException("Path is incorect!");
		}
		File dir = new File(path);
		if(!dir.exists()){
			throw new IllegalArgumentException("Path is incorect!");
		}
		if(!dir.isDirectory()){
			throw new IllegalArgumentException("Path is not directory!");
		}
		File[] allFile = findAllFiles(dir);
		return removeDirectoryFromList(allFile);
	}
}
